import type { LoginData } from '@/types/login';

const USER_INFO_KEY = 'userInfo';
const TOKEN_KEY = 'token';

const config = 'config';
export const getUserInfo = () => {
  const result = useCookie<LoginData>(USER_INFO_KEY, {});

  return result!.value;
};

export const setUserInfo = (userInfo: LoginData) => {
  const result = useCookie<LoginData>(USER_INFO_KEY, {});

  result!.value = userInfo;
};

export const removeUserInfo = () => {
  const result = useCookie(USER_INFO_KEY, {});

  result!.value = null;
};

export const getToken = () => {
  const result = useCookie<string>(TOKEN_KEY, {});

  return result!.value;
};

export const setToken = (token: string) => {
  const result = useCookie<string>(TOKEN_KEY, {});
  result!.value = token;
};

export const removeToken = () => {
  const result = useCookie(TOKEN_KEY, {});

  result!.value = null;
};
export const getConfig = () => {
  const result = useCookie<string>(config, {});
  return result!.value;
};

export const setConfig = (config1: string) => {
  const result = useCookie<string>(config, {});
  result!.value = config1;
};
